#include "../include/game.h"
#include "../include/level.h"
#include "../include/map.h"

struct s_level{
	t_map* maps; // array of the level's maps
	ushort nb_maps; // nb maps of the level
	ushort cur_map; // the current map
	ushort nb_level;
};

t_level level_get_level(int num) {
	t_level level = malloc(sizeof(struct s_level));
	level->nb_level=num;
	switch(num) {
	case 0 :
		level->nb_maps = 3;
		level->cur_map = 0;
		level->maps = malloc(sizeof (*level->maps));
		level->maps[0] = map_load("map/map_1_1");
		level->maps[1] = map_load("map/map_1_2");
		level->maps[2] = map_load("map/map_2_1");
		return level;
		break;
	/*case 1:
		level->nb_maps = 3;
		level->cur_map = 0;
		level->maps[0] = map_load("map/map_2_1");
		level->maps[1] = map_load("map/map_2_2");
		level->maps[2] = map_load("map/map_2_3");
		return level;
		break;*/
	}
	return NULL;
}

t_map level_get_curr_map(t_level level) {
	return level->maps[level->cur_map];
}

t_map level_get_map(t_level level, int num) {
	assert(num <= level->nb_maps);
	return level->maps[num];
}

void level_free(t_level level) {
	for(int i = 0; i < level->nb_maps; i++) {
		map_free(level->maps[i]);
	}
	free(level->maps);
}

void level_display(t_level level, SDL_Surface* screen) {
	map_display(level->maps[level->cur_map], screen);
}

ushort level_get_nb_level(t_level level){
	assert(level);

	return level->nb_level;
}


ushort level_inc_nb_level(t_level level){
	assert(level);

	if(level->nb_level < NB_LEVEL_MAX)
		level->nb_level +=1;
	return level->nb_level;
}

ushort level_dec_nb_level(t_level level){
	assert(level);

	if(level->nb_level)
		level->nb_level -=1;
	return level->nb_level;
}


ushort level_get_cur_map(t_level level){
	assert(level);

	return level->cur_map;
}

ushort level_inc_cur_map(t_level level){
	assert(level);

	if(level->cur_map < level->nb_maps)
		level->cur_map +=1;

	return level->cur_map;
}

ushort level_dec_cur_map(t_level level){
	assert(level);

	if(level->cur_map)
		level->cur_map -=1;

	return level->cur_map;
}

ushort level_get_nb_maps(t_level level){
	assert(level);

	return level->nb_maps;
}
